package b;

import h.RequestContext;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import d.ConnectionManager;
import d.QueryCallback;

public class Area extends Entity {
	private String areaCode;
	private String currency;
	private String areaName;

	public Area(String areaCode, String currency, String areaName) {
		this.areaCode = areaCode;
		this.currency = currency;
		this.areaName = areaName;
	}
	
	public String getCode(){
		return areaCode;
	}
	
	public String getCurrency(){
		return currency;
	}
	
	public String getAreaName() {
		return areaName;
	}
	
	private static Area parseCurrentResult(ResultSet rs) {
		Area n = null;
		try {
			n = new Area(rs.getString("areaCode"),rs.getString("currency"),rs.getString("areaName"));
		}catch(SQLException e){
			e.printStackTrace();
		}
		return n;
	}
	
	public static Iterator<Entity> list(RequestContext rc) {
		return ConnectionManager.executeQuery("SELECT areaCode,currency,areaName FROM Area ORDER BY currency", new QueryCallback<Iterator<Entity>>(){
			@Override
			public Iterator<Entity> processResultset(ResultSet rs)
					throws SQLException {
				LinkedList<Entity> areas = new LinkedList<Entity>();
				while(rs.next()) {
					areas.add(parseCurrentResult(rs));
				}
				return areas.iterator();
			}
		});
	}

	@Override
	public boolean save() {
		return false;
	}

	@Override
	public void update(Map<String, String> params) {}

}
